package cn.com.cifi.mars.web.action.sys;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.alibaba.fastjson.JSONArray;

import cn.com.cifi.mars.bean.bo.SysLogBO;
import cn.com.cifi.mars.bean.vo.sys.req.SaveSysPositionGroupPermissionReqParam;
import cn.com.cifi.mars.bean.vo.sys.rsp.PositionGroupPermissionVo;
import cn.com.cifi.mars.common.base.BaseAction;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.constant.LogEventEnum;
import cn.com.cifi.mars.constant.LogSrcEnum;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.service.SysLogService;
import cn.com.cifi.mars.service.SysPositionGroupPermissionService;
import cn.com.cifi.mars.util.WebUtils;

/**
 * <p>
 * 岗位组功能权限关联表 前端控制器
 * </p>
 *
 * @author yyd
 * @since 2019-09-20
 */
@RestController
public class SysPositionGroupPermissionController extends BaseAction implements ISysPositionGroupPermissionController{

	@Autowired
	private SysPositionGroupPermissionService sysPositionGroupPermissionService;
	
	@Autowired
	private SysLogService sysLogService;
	
	/**
	 * 设置岗位组功能权限
	 */
	@Override
	public R<String> createSysPositionGroupPermission(String apiVersion, SaveSysPositionGroupPermissionReqParam param) {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		IdmUser user = getOperator();
		// 新增日志
		SysLogBO bo = new SysLogBO();
		bo.setEvent(LogEventEnum.ADD);
		bo.setSource(LogSrcEnum.PC);
		bo.setIp(WebUtils.getIpAddr(request));
		bo.setUrl(WebUtils.getUrl(request));
		bo.setModule("权限管理");
		bo.setTitle("设置岗位组功能权限");
		bo.setContent("设置岗位组功能权限");
		boolean msg = sysLogService.add(bo, user.getAlias());
		return ok(sysPositionGroupPermissionService.add(param, user.getAlias()));
	}

	/**
	 * 显示岗位组功能权限
	 */
	@Override
	public R<PositionGroupPermissionVo> getSysPositionGroupPermissionTree(String apiVersion, String positionGroupId) {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		IdmUser user = getOperator();
		// 新增日志
		SysLogBO bo = new SysLogBO();
		bo.setEvent(LogEventEnum.BROWSE);
		bo.setSource(LogSrcEnum.PC);
		bo.setIp(WebUtils.getIpAddr(request));
		bo.setUrl(WebUtils.getUrl(request));
		bo.setModule("权限管理");
		bo.setTitle("显示岗位组功能权限");
		bo.setContent("显示岗位组功能权限");
		boolean msg = sysLogService.add(bo, user.getAlias());
		return ok(sysPositionGroupPermissionService.querySysPositionGroupPermissionTree(positionGroupId));
	}

}
